package com.laowang.common.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Auther laowang
 * @Date 2023/6/14
 * @Description
 */
public class NumUtil {

    public static Integer getType(Integer num) {

        //判断是炸弹号
        String number = String.valueOf(num);
        int length = number.length();
        if (length == 2 && num == 12){
            System.out.println("三联顺");
            return 1;
        }
        if (length == 2){
            System.out.println("普通号");
            return 0;
        }
        Boolean iszd = false;
        for (int i = 0; i < length - 1; i++) {
            if (number.length() == 4 && number.charAt(0) == number.charAt(1) && number.charAt(1) == number.charAt(2)
                && number.charAt(2) == number.charAt(3)
            ) {

                iszd = true;
            }
        }


        char[] split = number.toCharArray();
        //String[] split = StringUtils.split(number, "");
        List<Integer> collect2 = new ArrayList<>();
        for (char s : split) {
            collect2.add((int) s);
        }
        System.out.println("collect2:" + collect2);
        //3连顺
        Boolean isslx = false;
        //四连顺
        Boolean issilx = true;
        //豹子
        Boolean isbaozi = false;
        List<Integer> integerList = new ArrayList<>();

        for (int i = 0; i < collect2.size() - 1; i++) {
            integerList.add(collect2.get(i + 1) - collect2.get(i));

        }
        System.out.println("integerList"+integerList);
        //如果四连顺 豹子 三联顺  这里就是3位
        if (integerList.size() == 3) {
            for (Integer integer : integerList) {
                if (integer != 1) {
                    issilx = false;
                }
            }
            // 三联顺
            for (int i = 0; i < integerList.size(); i++) {
                if (integerList.get(2)==1 &&   integerList.get(1) == 1) {
                    isslx = true;

                }
                if (integerList.get(1) ==1 &&  integerList.get(0) == 1) {
                    isslx = true;

                }
            }


            //豹子
            for (int i = 0; i < integerList.size(); i++) {

                if (integerList.get(0) == 0 && integerList.get(1) == 0) {
                    isbaozi = true;

                }
                if (integerList.get(1) == 0 && integerList.get(2) == 0) {
                    isbaozi = true;

                }

            }
        }


        //如果三连顺 豹子 这里就是2位
        if (integerList.size() == 2) {
            issilx = false;
            if (integerList.get(1) ==1 && integerList.get(0) == 1) {
                isslx = true;
            }

            for (Integer integer : integerList) {
                if (integer != 0) {
                    isbaozi = false;
                }
            }

        }


        System.out.println("三联顺:" + isslx);
        System.out.println("思连顺:" + issilx);
        System.out.println("豹子:" + isbaozi);

        //1三连号,2四连号,3豹子号,4炸弹号,0普通号
        if (iszd) {
            //是炸弹
            return 4;
        } else if (issilx) {
            //四连顺
            return 2;

        } else if (isslx) {
            //三连顺
            return 1;
        } else if (isbaozi) {
            //豹子
            return 3;
        } else {
            //普通号
            return 0;
        }

    }

    public static void main(String[] args) {
        Integer type = getType(1789);
        System.out.println(type);
    }
}
